<html>
<!-- =====================================================================

  File:      Generated file for Adventure Works Cycles Storefront Sample
  Summary:   Self-documentation for application
  Date:	     June 16, 2003

=====================================================================

  This file is part of the Microsoft SQL Server Code Samples.
  Copyright (C) 2003 Microsoft Corporation.  All rights reserved.

This source code is intended only as a supplement to Microsoft
Development Tools and/or on-line documentation.  See these other
materials for detailed information regarding Microsoft code samples.

THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

======================================================= -->
<head>
  <link rel=stylesheet href=style.css>
</head>
<body>
<div class=SourcePanel style="font-size:12">
<pre style="background-color:white">
<span style="color: #0000FF"><strong>using</strong></span> <span style="color: #2040a0">System</span><span style="color: #4444FF">;</span>
<span style="color: #0000FF"><strong>using</strong></span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Collections</span><span style="color: #4444FF">;</span>
<span style="color: #0000FF"><strong>using</strong></span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">ComponentModel</span><span style="color: #4444FF">;</span>
<span style="color: #0000FF"><strong>using</strong></span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Data</span><span style="color: #4444FF">;</span>
<span style="color: #0000FF"><strong>using</strong></span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Drawing</span><span style="color: #4444FF">;</span>
<span style="color: #0000FF"><strong>using</strong></span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Web</span><span style="color: #4444FF">;</span>
<span style="color: #0000FF"><strong>using</strong></span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Web</span>.<span style="color: #2040a0">UI</span><span style="color: #4444FF">;</span>
<span style="color: #0000FF"><strong>using</strong></span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Web</span>.<span style="color: #2040a0">UI</span>.<span style="color: #2040a0">WebControls</span><span style="color: #4444FF">;</span>
<span style="color: #0000FF"><strong>using</strong></span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Web</span>.<span style="color: #2040a0">UI</span>.<span style="color: #2040a0">HtmlControls</span><span style="color: #4444FF">;</span>
<span style="color: #0000FF"><strong>using</strong></span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Web</span>.<span style="color: #2040a0">Caching</span><span style="color: #4444FF">;</span>
<span style="color: #0000FF"><strong>using</strong></span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Text</span><span style="color: #4444FF">;</span>
<span style="color: #0000FF"><strong>using</strong></span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Globalization</span><span style="color: #4444FF">;</span>

<span style="color: #008000">/* =====================================================================

  File:      _Menu.ascx.cs for Adventure Works Cycles Storefront Sample
  Summary:   Master page user control which displays a tree of product categories and subcategories.  Provides the
			 the ability to quickly navigate the product catalog.
  Date:	     June 16, 2003

---------------------------------------------------------------------

  This file is part of the Microsoft SQL Server Code Samples.
  Copyright (C) Microsoft Corporation.  All rights reserved.

This source code is intended only as a supplement to Microsoft
Development Tools and/or on-line documentation.  See these other
materials for detailed information regarding Microsoft code samples.

THIS CODE AND INFORMATION ARE PROVIDED &quot;AS IS&quot; WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

======================================================= */</span>

<span style="color: #0000FF"><strong>namespace</strong></span> <span style="color: #2040a0">Microsoft</span>.<span style="color: #2040a0">Samples</span>.<span style="color: #2040a0">SqlServer</span> 
<span style="color: #4444FF"><strong>{</strong></span>

    <span style="color: #0000FF"><strong>public</strong></span> <span style="color: #2040a0">partial</span> <span style="color: #0000FF"><strong>class</strong></span> <span style="color: #2040a0">MenuControl</span> <span style="color: #4444FF">:</span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Web</span>.<span style="color: #2040a0">UI</span>.<span style="color: #2040a0">UserControl</span>
    <span style="color: #4444FF"><strong>{</strong></span>


        <span style="color: #008000">//*******************************************************</span>
        <span style="color: #008000">//</span>
        <span style="color: #008000">// The Page_Load event on this page is used to obtain</span>
        <span style="color: #008000">// from a database a list of all product categories</span>
        <span style="color: #008000">// and databind it to an asp:datalist control.</span>
        <span style="color: #008000">//</span>
        <span style="color: #008000">// To optimize performance, this user control is output </span>
        <span style="color: #008000">// cached (varying based on the categoryId and selection</span>
        <span style="color: #008000">// passed through the querystring.    </span>
        <span style="color: #008000">//</span>
        <span style="color: #008000">//*******************************************************</span>

		<span style="color: #0000FF"><strong>private</strong></span> <span style="color: #0000FF"><strong>void</strong></span> <span style="color: #2040a0">Page_Load</span><span style="color: #4444FF">(</span><span style="color: #2040a0">object</span> <span style="color: #2040a0">sender</span>, <span style="color: #2040a0">System</span>.<span style="color: #2040a0">EventArgs</span> <span style="color: #2040a0">e</span><span style="color: #4444FF">)</span>
		<span style="color: #4444FF"><strong>{</strong></span>
			<span style="color: #0000FF"><strong>if</strong></span> <span style="color: #4444FF">(</span><span style="color: #2040a0">TreeView1</span>.<span style="color: #2040a0">Nodes</span>.<span style="color: #2040a0">Count</span> <span style="color: #4444FF">&gt;</span> <span style="color: #FF0000">0</span><span style="color: #4444FF">)</span> <span style="color: #0000FF"><strong>return</strong></span><span style="color: #4444FF">;</span>

			<span style="color: #2040a0">String</span> <span style="color: #2040a0">expansionParam</span> <span style="color: #4444FF">=</span> <span style="color: #2040a0">Request</span>.<span style="color: #2040a0">Params</span><span style="color: #4444FF">[</span><span style="color: #444444">&quot;expansion&quot;</span><span style="color: #4444FF">]</span><span style="color: #4444FF">;</span>
			<span style="color: #2040a0">String</span> <span style="color: #2040a0">selectionParam</span> <span style="color: #4444FF">=</span> <span style="color: #2040a0">Request</span>.<span style="color: #2040a0">Params</span><span style="color: #4444FF">[</span><span style="color: #444444">&quot;selection&quot;</span><span style="color: #4444FF">]</span><span style="color: #4444FF">;</span>
			<span style="color: #0000FF"><strong>int</strong></span> <span style="color: #2040a0">expansionIndex</span> <span style="color: #4444FF">=</span> <span style="color: #4444FF">(</span><span style="color: #2040a0">expansionParam</span> <span style="color: #4444FF">=</span><span style="color: #4444FF">=</span> <span style="color: #2040a0">null</span><span style="color: #4444FF">)</span> ? <span style="color: #4444FF">-</span><span style="color: #FF0000">1</span> <span style="color: #4444FF">:</span> <span style="color: #2040a0">Int32</span>.<span style="color: #2040a0">Parse</span><span style="color: #4444FF">(</span><span style="color: #2040a0">expansionParam</span>, <span style="color: #2040a0">CultureInfo</span>.<span style="color: #2040a0">InvariantCulture</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>
			<span style="color: #0000FF"><strong>int</strong></span> <span style="color: #2040a0">selectionIndex</span> <span style="color: #4444FF">=</span> <span style="color: #4444FF">(</span><span style="color: #2040a0">selectionParam</span> <span style="color: #4444FF">=</span><span style="color: #4444FF">=</span> <span style="color: #2040a0">null</span><span style="color: #4444FF">)</span> ? <span style="color: #4444FF">-</span><span style="color: #FF0000">1</span> <span style="color: #4444FF">:</span> <span style="color: #2040a0">Int32</span>.<span style="color: #2040a0">Parse</span><span style="color: #4444FF">(</span><span style="color: #2040a0">selectionParam</span>, <span style="color: #2040a0">CultureInfo</span>.<span style="color: #2040a0">InvariantCulture</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>

			<span style="color: #2040a0">TreeView1</span>.<span style="color: #2040a0">SelectedNodeStyle</span>.<span style="color: #2040a0">ForeColor</span> <span style="color: #4444FF">=</span> <span style="color: #2040a0">Color</span>.<span style="color: #2040a0">White</span><span style="color: #4444FF">;</span>


			<span style="color: #008000">// Obtain list of menu categories and databind to tree control</span>
			<span style="color: #2040a0">ProductsDB</span> <span style="color: #2040a0">products</span> <span style="color: #4444FF">=</span> <span style="color: #0000FF"><strong>new</strong></span> <span style="color: #2040a0">ProductsDB</span><span style="color: #4444FF">(</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>

			<span style="color: #2040a0">DataSet</span> <span style="color: #2040a0">productsDs</span> <span style="color: #4444FF">=</span> <span style="color: #2040a0">products</span>.<span style="color: #2040a0">GetProductTree</span><span style="color: #4444FF">(</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>
			<span style="color: #0000FF"><strong>if</strong></span> <span style="color: #4444FF">(</span><span style="color: #2040a0">productsDs</span>.<span style="color: #2040a0">Tables</span>.<span style="color: #2040a0">Count</span> <span style="color: #4444FF">&gt;</span> <span style="color: #FF0000">1</span><span style="color: #4444FF">)</span>
			<span style="color: #4444FF"><strong>{</strong></span>
				<span style="color: #2040a0">DataTable</span> <span style="color: #2040a0">categoriesTable</span> <span style="color: #4444FF">=</span> <span style="color: #2040a0">productsDs</span>.<span style="color: #2040a0">Tables</span><span style="color: #4444FF">[</span><span style="color: #444444">&quot;ProductCategory&quot;</span><span style="color: #4444FF">]</span><span style="color: #4444FF">;</span>
				<span style="color: #2040a0">DataTable</span> <span style="color: #2040a0">subcategoriesTable</span> <span style="color: #4444FF">=</span> <span style="color: #2040a0">productsDs</span>.<span style="color: #2040a0">Tables</span><span style="color: #4444FF">[</span><span style="color: #444444">&quot;ProductSubcategory&quot;</span><span style="color: #4444FF">]</span><span style="color: #4444FF">;</span>
				<span style="color: #0000FF"><strong>int</strong></span> <span style="color: #2040a0">categoryNumber</span> <span style="color: #4444FF">=</span> <span style="color: #FF0000">0</span><span style="color: #4444FF">;</span>
				<span style="color: #0000FF"><strong>int</strong></span> <span style="color: #2040a0">subcategoryNumber</span> <span style="color: #4444FF">=</span> <span style="color: #FF0000">0</span><span style="color: #4444FF">;</span>

				<span style="color: #2040a0">foreach</span> <span style="color: #4444FF">(</span><span style="color: #2040a0">DataRow</span> <span style="color: #2040a0">cdr</span> <span style="color: #2040a0">in</span> <span style="color: #2040a0">categoriesTable</span>.<span style="color: #2040a0">Rows</span><span style="color: #4444FF">)</span>
				<span style="color: #4444FF"><strong>{</strong></span>
					<span style="color: #2040a0">TreeNode</span> <span style="color: #2040a0">categoryNode</span> <span style="color: #4444FF">=</span> <span style="color: #0000FF"><strong>new</strong></span> <span style="color: #2040a0">TreeNode</span><span style="color: #4444FF">(</span><span style="color: #2040a0">cdr</span><span style="color: #4444FF">[</span><span style="color: #444444">&quot;Name&quot;</span><span style="color: #4444FF">]</span>.<span style="color: #2040a0">ToString</span><span style="color: #4444FF">(</span><span style="color: #4444FF">)</span>, <span style="color: #2040a0">cdr</span><span style="color: #4444FF">[</span><span style="color: #444444">&quot;ProductCategoryID&quot;</span><span style="color: #4444FF">]</span>.<span style="color: #2040a0">ToString</span><span style="color: #4444FF">(</span><span style="color: #4444FF">)</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>
					<span style="color: #2040a0">TreeView1</span>.<span style="color: #2040a0">Nodes</span>.<span style="color: #2040a0">Add</span><span style="color: #4444FF">(</span><span style="color: #2040a0">categoryNode</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>
					<span style="color: #2040a0">foreach</span> <span style="color: #4444FF">(</span><span style="color: #2040a0">DataRow</span> <span style="color: #2040a0">scdr</span> <span style="color: #2040a0">in</span> <span style="color: #2040a0">cdr</span>.<span style="color: #2040a0">GetChildRows</span><span style="color: #4444FF">(</span><span style="color: #444444">&quot;CategorySubCategories&quot;</span><span style="color: #4444FF">)</span><span style="color: #4444FF">)</span>
					<span style="color: #4444FF"><strong>{</strong></span>
						<span style="color: #2040a0">TreeNode</span> <span style="color: #2040a0">subcategoryNode</span> <span style="color: #4444FF">=</span> <span style="color: #0000FF"><strong>new</strong></span> <span style="color: #2040a0">TreeNode</span><span style="color: #4444FF">(</span><span style="color: #2040a0">scdr</span><span style="color: #4444FF">[</span><span style="color: #444444">&quot;Name&quot;</span><span style="color: #4444FF">]</span>.<span style="color: #2040a0">ToString</span><span style="color: #4444FF">(</span><span style="color: #4444FF">)</span>, <span style="color: #2040a0">scdr</span><span style="color: #4444FF">[</span><span style="color: #444444">&quot;ProductSubcategoryID&quot;</span><span style="color: #4444FF">]</span>.<span style="color: #2040a0">ToString</span><span style="color: #4444FF">(</span><span style="color: #4444FF">)</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>
						<span style="color: #2040a0">subcategoryNode</span>.<span style="color: #2040a0">NavigateUrl</span> <span style="color: #4444FF">=</span> <span style="color: #2040a0">String</span>.<span style="color: #2040a0">Format</span><span style="color: #4444FF">(</span><span style="color: #444444">&quot;productslist.aspx?SubcategoryID={0}&amp;expansion={1}&amp;selection={2}&quot;</span>,
																	<span style="color: #2040a0">subcategoryNode</span>.<span style="color: #2040a0">Value</span>, <span style="color: #2040a0">categoryNumber</span>, <span style="color: #2040a0">subcategoryNumber</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>
						<span style="color: #2040a0">categoryNode</span>.<span style="color: #2040a0">ChildNodes</span>.<span style="color: #2040a0">Add</span><span style="color: #4444FF">(</span><span style="color: #2040a0">subcategoryNode</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>
						<span style="color: #0000FF"><strong>if</strong></span> <span style="color: #4444FF">(</span><span style="color: #2040a0">subcategoryNumber</span> <span style="color: #4444FF">=</span><span style="color: #4444FF">=</span> <span style="color: #2040a0">selectionIndex</span><span style="color: #4444FF">)</span> <span style="color: #2040a0">subcategoryNode</span>.<span style="color: #2040a0">Select</span><span style="color: #4444FF">(</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>
						<span style="color: #2040a0">subcategoryNumber</span> <span style="color: #4444FF">+</span><span style="color: #4444FF">=</span> <span style="color: #FF0000">1</span><span style="color: #4444FF">;</span>
					<span style="color: #4444FF"><strong>}</strong></span>
					<span style="color: #0000FF"><strong>if</strong></span> <span style="color: #4444FF">(</span><span style="color: #2040a0">categoryNumber</span> <span style="color: #4444FF">=</span><span style="color: #4444FF">=</span> <span style="color: #2040a0">expansionIndex</span><span style="color: #4444FF">)</span> <span style="color: #2040a0">categoryNode</span>.<span style="color: #2040a0">Expand</span><span style="color: #4444FF">(</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>
					<span style="color: #2040a0">categoryNumber</span> <span style="color: #4444FF">+</span><span style="color: #4444FF">=</span> <span style="color: #FF0000">1</span><span style="color: #4444FF">;</span>
				<span style="color: #4444FF"><strong>}</strong></span>
			<span style="color: #4444FF"><strong>}</strong></span>
		<span style="color: #4444FF"><strong>}</strong></span>

        <span style="color: #0000FF"><strong>private</strong></span> <span style="color: #0000FF"><strong>void</strong></span> <span style="color: #2040a0">Page_Init</span><span style="color: #4444FF">(</span><span style="color: #2040a0">object</span> <span style="color: #2040a0">sender</span>, <span style="color: #2040a0">EventArgs</span> <span style="color: #2040a0">e</span><span style="color: #4444FF">)</span> <span style="color: #4444FF"><strong>{</strong></span>
            <span style="color: #008000">//</span>
            <span style="color: #008000">// CODEGEN: This call is required by the ASP.NET Web Form Designer.</span>
            <span style="color: #008000">//</span>
            <span style="color: #2040a0">InitializeComponent</span><span style="color: #4444FF">(</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>
        <span style="color: #4444FF"><strong>}</strong></span>

<span style="color: #0000ff"><strong>		#region Web Form Designer generated code</strong></span>
        <span style="color: #008000">/// &lt;summary&gt;</span>
        <span style="color: #008000">/// Required method for Designer support - do not modify</span>
        <span style="color: #008000">/// the contents of this method with the code editor.</span>
        <span style="color: #008000">/// &lt;/summary&gt;</span>
        <span style="color: #0000FF"><strong>private</strong></span> <span style="color: #0000FF"><strong>void</strong></span> <span style="color: #2040a0">InitializeComponent</span><span style="color: #4444FF">(</span><span style="color: #4444FF">)</span> <span style="color: #4444FF"><strong>{</strong></span>    

		<span style="color: #4444FF"><strong>}</strong></span>

<span style="color: #0000ff"><strong>		#endregion</strong></span>
    <span style="color: #4444FF"><strong>}</strong></span>
<span style="color: #4444FF"><strong>}</strong></span>

</pre>
